package com.wt.admin.util;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.util.List;

public class CodeGenerator {

    private static final String PROJECT_PATH = System.getProperty("user.dir") + "/admin3/";

    public interface DataBase {
        String URL = "jdbc:mysql://127.0.0.1:3306/admin?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&remarks=true&useInformationSchema=true&tinyInt1isBit=true";
        String USERNAME = "root";
        String PASSWORD = "superAdmin@2025";
        String AUTH = "uncle";
    }

    public interface PackageName {
        String BASE = "com.wt.admin";
        String ENTITY = "domain.entity";
        String MAPPER = "mapper";
        String SERVICE = "service";
        String SERVICE_IMPL = SERVICE + ".impl";
        String MAPPER_XML = "mapper.xml";
    }

    public interface TableStrategy {
        List<String> TABLES = List.of("text");
    }


    private void generate() {
        FastAutoGenerator.create(DataBase.URL, DataBase.USERNAME, DataBase.PASSWORD)
                .globalConfig(builder -> builder
                                .author(DataBase.AUTH)
//                        .enableSwagger() // 开启 swagger 模式
                                .outputDir(PROJECT_PATH + "/src/main/java")
                                .commentDate("yyyy-MM-dd")
                )
                .packageConfig(builder -> builder
                        .parent(PackageName.BASE)
                        .entity(PackageName.ENTITY)
                        .mapper(PackageName.MAPPER)
                        .service(PackageName.SERVICE)
                        .serviceImpl(PackageName.SERVICE_IMPL)
                        .xml(PackageName.MAPPER_XML)
                )
                .strategyConfig(builder -> builder
                        .addInclude(TableStrategy.TABLES)
                        .entityBuilder()
                        .enableLombok()
                )
                .templateEngine(new FreemarkerTemplateEngine())
                .execute();
    }

    public static void main(String[] args) {
        new CodeGenerator().generate();
    }
}
